package uc.org.jkas.app.admin;
import java.util.HashMap;
import uc.org.jkas.model.AdminsM;
public class Passport extends BackBase
{  
	@SuppressWarnings("unchecked")
	public void reset()
	{ if(IS_POST())
		{String res=strc("{\"code\":400,\"msg\":\"",L("modifyfaild"),"\"}");
		 String oldpass=P("oldpass");
	     String newpass=P("newpass");
		 String confirmpass=P("confirmpass");
		 HashMap<String,String> user=(HashMap<String,String>)session("user");
		 if(newpass.equals(confirmpass))
			{
		      if(md5(strc(md5(oldpass),user.get("salt"))).equals(user.get("password")))
			   { AdminsM ams=new AdminsM();
			     HashMap<String,Object>params=new HashMap<String,Object>();
				  int salt=random(100000,999999);
				  String password=md5(strc(md5(newpass),salt));
				  params.put("password",password);
				  params.put("salt",salt);
			     if(ams.update(strc("uid=",user.get("uid")),params)>0)
				   {sessdel("user");
				    res="{\"code\":200,\"msg\":\"ok\"}";
				   }
			   }
			    else
			     {res=strc("{\"code\":202,\"msg\":\"",L("wrongoldpass"),"\"}");
			     }
			 }
			  else
			    {res=strc("{\"code\":203,\"msg\":\"",L("pass_not_match"),"\"}");
			    }
           echo(res);
		}
		else
		{display();
		}
	}
}